//
//  UIViewController+JJWeb.m
//  ZMUnderFrameWorkDemo
//
//  Created by MAC on 2020/1/8.
//  Copyright © 2020 MAC. All rights reserved.
//

#import "UIViewController+JJWeb.h"
#import "ZMWkwebViewVC.h"

@implementation UIViewController (JJWeb)

/// 加载纯外部链接网页
-(void)jj_webView:(NSString *)navTitle
              url:(NSString *)url
  viewTransitions:(ViewTransitions)view{
    
    ZMWkwebViewVC *vc = [ZMWkwebViewVC new];
    vc.navType = NaviTypeShowDefNav;
    vc.navTitle = navTitle;
    vc.vTransitions = view;
    [vc loadWebURLSring:url];
    
    if (view==ViewTransitionsPresent) {
        RTRootNavigationController *nav=[[RTRootNavigationController alloc]initWithRootViewController:vc];
        nav.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentViewController:nav animated:YES completion:nil];
    }else{
        vc.hidesBottomBarWhenPushed=YES;
        if ([self isKindOfClass:[RTRootNavigationController class]]) {
            [(RTRootNavigationController *)self pushViewController:vc animated:YES];
        }else{
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}

/// 加载本地网页
-(void)jj_webView:(NSString *)navTitle
              url:(NSString *)url
  viewTransitions:(ViewTransitions)view
            block:(void (^)(NSDictionary *okDic))block{
    
    ZMWkwebViewVC *vc = [[ZMWkwebViewVC alloc] init];
    vc.navType = NaviTypeShowDefNav;
    vc.navTitle = navTitle;
    vc.vTransitions = view;
    [vc loadWebURLSring:url];
    vc.successfulBlock = ^(NSDictionary *okDic) {
        !block?:block(okDic);
    };
    if (view==ViewTransitionsPresent) {
        RTRootNavigationController *nav=[[RTRootNavigationController alloc]initWithRootViewController:vc];
        nav.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentViewController:nav animated:YES completion:nil];
        
    }else{
        vc.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

/// 加载外部链接POST请求
-(void)jj_loadWebHTMLSring:(NSString *)navTitle
                       url:(NSString *)url
           viewTransitions:(ViewTransitions)view{
    
    ZMWkwebViewVC *vc = [[ZMWkwebViewVC alloc] init];
    vc.navType = NaviTypeShowDefNav;
    vc.navTitle = navTitle;
    vc.vTransitions = view;
    [vc loadWebHTMLSring:url];
    
    if (view==ViewTransitionsPresent) {
        RTRootNavigationController *nav=[[RTRootNavigationController alloc]initWithRootViewController:vc];
        nav.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentViewController:nav animated:YES completion:nil];
        
    }else{
        vc.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
}


@end
